package com.etoak.service.impl;


import com.etoak.bean.District;
import com.etoak.bean.Homestay;
import com.etoak.bean.HomestayVO;
import com.etoak.bean.Page;
import com.etoak.mapper.HomestayMapper;
import com.etoak.service.HomestayMaService;
import com.etoak.service.HomestayService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class HomestayMaServiceImpl implements HomestayMaService {

    @Resource
    HomestayMapper mapper;

    @Override
    public Page select(Page page,HomestayVO homestay) {
        PageHelper.startPage(page.getPageNum(),page.getPageSize());
        List<HomestayVO> rooms = mapper.selectAll(homestay);
        PageInfo<HomestayVO> pageInfo = new PageInfo<>(rooms);
        page.setRows(rooms);
        page.setTotal(pageInfo.getTotal());
        return page;
    }

    @Override
    public HomestayVO queryHomestayByHid(HomestayVO hotel) {
        return mapper.queryHomestayByHid(hotel);
    }

    @Override
    public List<District> selectDictByName(String name, Integer level) {
        return mapper.selectDictByName(name,level);
    }

    @Override
    public int add(Homestay homestay) {
        return mapper.add(homestay);
    }

    @Override
    public int update(Homestay homestay) {
        return mapper.update(homestay);
    }

    @Override
    public int del(Integer id) {
        return mapper.del(id);
    }

    @Override
    public Page selectHomestay(Page page, HomestayVO homestay) {
        PageHelper.startPage(page.getPageNum(),page.getPageSize());
        List<HomestayVO> rooms = mapper.selectHomestay(homestay);
        PageInfo<HomestayVO> pageInfo = new PageInfo<>(rooms);
        page.setRows(rooms);
        page.setTotal(pageInfo.getTotal());
        return page;
    }


}
